package com.example.take_out_order.controller;

import com.example.take_out_order.common.PageResult;
import com.example.take_out_order.common.Result;
import com.example.take_out_order.common.lang.dto.OrdersCancelDTO;
import com.example.take_out_order.common.lang.dto.OrdersConfirmDTO;
import com.example.take_out_order.common.lang.dto.OrdersPageQueryDTO;
import com.example.take_out_order.common.lang.dto.OrdersRejectionDTO;
import com.example.take_out_order.common.lang.vo.OrderStatisticsVO;
import com.example.take_out_order.common.lang.vo.OrderVO;
import com.example.take_out_order.service.OrdersService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author FZ
 * @since 2024-07-09
 */
@Slf4j
@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Resource
    private OrdersService ordersService;

    /**
     * 订单搜索
     * @param source
     * @return
     */
    // @PostMapping("/conditionSearch")
    // public Result<PageResult> conditionSearch(@RequestBody OrdersPageQueryDTO source){
    //     log.info("source: {}", source);
    //     return Result.success(ordersService.conditionSearch(source));
    // }

    /**
     * 各个订单数量统计
     * @return
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        return Result.success(ordersService.statistics());
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> detail(@PathVariable("id")String id){
        return Result.success(ordersService.detail(id));
    }

    /**
     * 接单
     * @param source
     * @return
     */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO source){
        ordersService.confirm(source);
        return Result.success();
    }

    /**
     * 拒单
     * @param source
     * @return
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO source){
        ordersService.rejection(source);
        return Result.success();
    }

    /**
     * 取消订单
     * @param source
     * @return
     */
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO source){
        ordersService.cancel(source);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id")String id){
        ordersService.delivery(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id")String id){
        ordersService.complete(id);
        return Result.success();
    }
}
